var a = getApp();

Page({
    data: {
        data: [],
        priceDesc: ""
    },
    bindAreaBlur: function(a) {
        var t = a.currentTarget.dataset.index, e = a.detail.value, i = this.data.data;
        i[t].area = e, this.setData({
            data: i
        }), console.log(this.data.data);
    },
    bindPriceBlur: function(a) {
        var t = a.currentTarget.dataset.index, e = a.detail.value, i = this.data.data;
        i[t].price = e, this.setData({
            data: i
        }), console.log(this.data.data);
    },
    clickUp: function(a) {
        var t = a.currentTarget.dataset.index, e = this.data.data, i = e[t];
        e.splice(t, 1), console.log(e), e.splice(t - 1, 0, i), console.log(e), this.setData({
            data: e
        });
    },
    clickDel: function(a) {
        var t = a.currentTarget.dataset.index, e = this.data.data;
        e[t];
        e.splice(t, 1), this.setData({
            data: e
        });
    },
    clickMore: function(a) {
        var t = this.data.data;
        t = t.concat({
            area: "",
            price: ""
        }), this.setData({
            data: t
        });
    },
    bindOtherTextAreaBlur: function(a) {
        console.log(a.detail.value), this.setData({
            priceDesc: a.detail.value
        });
    },
    clickSave: function(a) {
        this.save();
    },
    loadData: function() {
        var t = this;
        a.network.post({
            url: a.url.listPrice,
            params: {},
            before: function() {
                wx.showNavigationBarLoading();
            },
            success: function(e) {
                if (1 == e.data.result) {
                    var i = e.data.data.prices;
                    t.setData({
                        data: i
                    });
                } else a.util.showToast(e.data.message);
            },
            fail: function() {
                a.util.showToast("获取数据失败");
            },
            complete: function() {
                wx.hideNavigationBarLoading(), wx.stopPullDownRefresh();
            }
        });
    },
    save: function() {
        var t = this, e = JSON.stringify(this.data.data);
        a.network.post({
            url: a.url.submitPrice,
            params: {
                prices: e,
                priceDesc: t.data.priceDesc
            },
            before: function() {
                wx.showNavigationBarLoading();
            },
            success: function(t) {
                if (1 == t.data.result) {
                    a.util.showToast(t.data.message);
                    var e = getCurrentPages();
                    e[e.length - 2].setData({
                        needUpdate: !0
                    }), setTimeout(function() {
                        wx.navigateBack({});
                    }, 1e3);
                } else a.util.showToast(t.data.message);
            },
            fail: function() {
                a.util.showToast("获取数据失败");
            },
            complete: function() {
                wx.hideNavigationBarLoading(), wx.stopPullDownRefresh();
            }
        });
    },
    onLoad: function(t) {
        this.loadData(), this.setData({
            priceDesc: a.globalData.userInfo.priceDesc
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {}
});